-- ReflexAction
-- create by zouyb
-- 反伤动作
require "game/ui/form/dungeon/UIDungeonMain"

ReflexAction = class("ReflexAction", function()
    return ActionBase.create();
end);
function ReflexAction.create(source, target)
    local self = ReflexAction.new();
    self.source = source;
    self.target = target;
    return self;
end

-- 构造函数
function ReflexAction:ctor()
end

-- 开始播放
function ReflexAction:play()
    --播放特效
    local pos;

    if not self.target or self.target.type ~= OBJECT_TYPE_MONSTER
       or self.target:isDead() or self.target:isBoss() then
        -- 不存在，不是怪物，死亡，BOSS 都不播放
        return;
    end

    local offset = cc.p(0, 0);
    if self.target ~= ME.user then
        pos = UIDungeonMgr:getCurLevel():getMonsterPos(self.target:getOwner());
        offset = cc.p(0, 33);
    else
        pos = UIDungeonMgr:getCurLevel():getHeroPos();
    end

    -- 反伤光效
    local addNode = cc.Node:create();
    addNode:setPosition(cc.pAdd(pos, offset));

    local effectNode = UIDungeonMgr:getCurLevel():getEffectParent();
    effectNode:addChild(addNode);

    -- 刺伤光效
    playEffect(addNode, 1242, 0, 60);

    local function callback()
        effectNode:removeChild(addNode);
    end

    performWithDelay(effectNode, callback, 0.5);
    return 0;
end

return ReflexAction;